package spring.module.scheduling;

import java.time.LocalTime;
import java.util.concurrent.Future;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/**
 * 异步任务
 * 
 * @author Lucky Yang

 */
@Slf4j
@Component
public class AsyncTask {
    @Async
    public Future<String> doTaskOne() throws Exception {
        LocalTime start = LocalTime.now();
        int costTime = Nap.random(1000);
        log.info("异步任务一[{}][{}]", costTime, start);

        return new AsyncResult<>("异步任务一完成");
    }

    @Async
    public Future<String> doTaskTwo() throws Exception {
        LocalTime start = LocalTime.now();
        int costTime = Nap.random(1000);
        log.info("异步任务二[{}][{}]", costTime, start);

        return new AsyncResult<>("异步任务二完成");
    }
}
